package com.gitee.zw.rule.config;

import com.gitee.zw.rule.service.RuleServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
@Slf4j
public class EngineStartupApplicationRunner implements ApplicationRunner {
    public static final String LOAD_RULES = "LOAD_RULES";
    @Autowired
    RuleServiceImpl service;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (Objects.equals(System.getProperty(LOAD_RULES), "N")) {
            log.info("Skipping rule loading...");
        } else {
            log.info("Loading rules into engine...");
            service.startUpEngine();
            log.info("Rules loaded.");
        }
    }
}
